<?php 
$this->headScript()->appendFile(_STATIC_HTTP . '/jquery/swfupload.js');
$this->headScript()->appendFile(_STATIC_HTTP . '/jquery/json2.js');
$this->headScript()->appendFile(_STATIC_HTTP . '/jquery/jcrop.js');
$this->headScript()->appendFile(_STATIC_HTTP . '/www/js/avatar.js');
$this->headLink()->prependStylesheet(_STATIC_HTTP . '/www/css/avatar.css');
?><form action="<?php echo $this->url('account/avatar/update');?>" method="post" id="SWFUploadForm">
<?php
echo $this->form()->hidden('sid', system_session::getId());
echo $this->form()->text('crop[p]', 1, array('class' => 'hidden'));
echo $this->form()->text('crop[x]', 0, array('class' => 'hidden'));
echo $this->form()->text('crop[y]', 0, array('class' => 'hidden'));
echo $this->form()->text('crop[w]', 0, array('class' => 'hidden'));
echo $this->form()->text('crop[h]', 0, array('class' => 'hidden'));
echo $this->form()->hidden('referer', $this->referer) . "\n";
?>
<div class="body">
	<table class="form">
		<tr>
			<td colspan="2" class="uploadPlaceHolder">
				<div class="button"><div id="uploadPlaceHolder"></div></div>
				<code><em><?php 
					$maxSize = @ini_get('upload_max_filesize');
					$extLimit = strtoupper(implode(' ', resource_config_avatar::getExtensions()));
					echo $this->language('仅支持 <b>{0}</b> 格式的图片文件，而且单个文件大小小于 <b>{1}</b>', array($extLimit, $maxSize));
				?></em></code>
			</td>
		</tr>
		<tr>
			<td class="preview l">
				<div class="pbox">
					<div id="original">
						<div class="processMask o5"></div>
						<div class="processBox o8">
							<div class="center"><div class="loading"></div></div>
							<p id="statusId">..</p>
							<div class="bar"><em id="percentBar"></em><b id="percentValue">0%</b></div>
						</div>
						<div id="avatarPhoto"></div>
						<span id="processIcon"><i class="o5"></i></span>
					</div>
				</div>
			</td>
			<td class="preview r">
				<div class="pbox" id="large"><span><img src="<?php echo $this->user->getAvatar()->getLarge(false);?>" /></span></div>
				<div class="pbox" id="middle"><span><img src="<?php echo $this->user->getAvatar()->getMiddle(false);?>" /></span></div>
				<div class="pbox" id="thumb"><span><img src="<?php echo $this->user->getAvatar()->getThumb(false);?>" /></span></div>
				<div class="pbox" id="small"><span><img src="<?php echo $this->user->getAvatar()->getSmall(false);?>" /></span></div>
				<code><i></i><em><?php 
					echo $this->language(
							'您上传的头像会自动生成 <b>{0}</b> 种尺寸，请注意尺寸的头像是否清晰。',
							array(count(resource_config_avatar::getSizes()))
						);
				?></em></code>
				<div class="clear"></div>
				<div id="saveButton" class="saveButton hidden">
					<button name="submit" type="submit" value="submit" onclick="return _avatar.save();"><?php echo $this->language('保存头像');?></button>
				</div>
				<?php if(count($this->list) > 1) { ?>
				<div class="clear"></div>
				<h3 class="yellow" style="margin-top:10px;"><?php echo $this->language('上传历史记录');?></h3>
				<div class="history">
					<ul>
						<?php
						foreach($this->list AS $row) {
							$isCurrent = $this->user->getAvatar()->getHash() == $row->getHash();
						?>
						<li>
							<label <?php if($isCurrent){echo ' class="current"';}?> for="h-<?php echo $row->getHash();?>" title="<?php echo $this->language('上传时间');?>: <?php echo $this->date($row->getCreationtime());?>">
							<img src="<?php echo $row->getAvatar()->getMiddle(false);?>" />
							</label>
							<?php if(!$isCurrent) {?>
							<em><input type="radio" name="hash" id="h-<?php echo $row->getHash();?>" value="<?php echo $row->getHash();?>" /></em>
							<?php } ?>
						</li>
						<?php } ?>
					</ul>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
				<div id="updateButton" class="saveButton">
					<button name="submit" type="submit" value="update" onclick="return _avatar.update();"><?php echo $this->language('更新头像');?></button>
				</div>
				<?php } ?>
			</td>
		</tr>
	</table>
</div>
</form>
<?php $this->headScript()->captureStart();?>
$(document).ready(function() {
	_avatar.setting = {
		upload_form: $('#SWFUploadForm'),
		upload_preview: '<?php echo $this->url('account/avatar/preview');?>'
	};
	_avatar.language.running = '<?php echo $this->language('图片正在上传，请稍等一下');?>..';
	_avatar.language.onlyforone = '<?php echo $this->language('只允许同时上传 1 张图片');?>..';
	_avatar.language.uploading = '<?php echo $this->language('正在上传，请稍后');?>..';
	_avatar.language.posting = '<?php echo $this->language('正在提交，请稍后');?>..';
	_avatar.swfu.flash_url = '<?php echo $this->baseUrl('/resource/swfupload.swf');?>';
	_avatar.swfu.upload_url = '<?php echo $this->url('account/avatar/upload');?>';
	_avatar.swfu.file_types = '<?php echo '*.' . implode(';*.', resource_config_avatar::getExtensions());?>';
	_avatar.swfu.button_placeholder_id = 'uploadPlaceHolder';
	_avatar.swfu.button_text = '<span class="theFont"><?php echo $this->language('从本地上传头像');?></span>';
	_avatar.swfu.file_types_description = '<?php echo $this->language('图片文件');?>';
	_avatar.SWFUpload = new SWFUpload(_avatar.swfu);
});
<?php $this->headScript()->captureEnd();?>